#ifndef QUAD_H
#define QUAD_H

#include "Hit/hittable.h"
#include "Hit/hittable_list.h"

class quad : public hittable {
public:
    quad(const point3& Q, const vec3& u, const vec3& v, std::shared_ptr<material> mat)
        : Q(Q), u(u), v(v), mat(mat)
    {
        auto n = cross(u, v);
        normal = unit_vector(n);
        D = dot(normal, Q);
        w = n / dot(n, n);

        area = n.length();// 利用叉乘的几何性质=平行四边形的面积

        set_bounding_box();
    }

    virtual void set_bounding_box();
    aabb bounding_box() const override { return bbox; }
    bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
    virtual bool is_interior(double a, double b, hit_record& rec) const;
    double pdf_value(const point3& origin, const vec3& direction) const override;
    vec3 random(const point3& origin) const override;

private:
    point3 Q;
    vec3 u, v;
    std::shared_ptr<material> mat;
    aabb bbox;
    vec3 normal;
    double D;
    vec3 w;
    double area;// 面积
};

extern std::shared_ptr<hittable_list> box(const point3& a, const point3& b, shared_ptr<material> mat);

#endif